import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_module/util/AbsState.dart';
import 'package:flutter_module/util/log.dart';

class PageB extends StatefulWidget {
  static const String routeName = "/PageB";

  const PageB();

  @override
  State<PageB> createState() => _PageBState();
}

class _PageBState extends AbsState<PageB> {
  int i=0;

  @override
  Widget build(BuildContext context) {
    logger.print('$widget build');
    return Scaffold(
      appBar: AppBar(
        leading: GestureDetector(
          child: Icon(Icons.arrow_back),
          onTap: () => onBackPressed(context),
        ),
        title: Text('Page B'),
      ),
      body:Column(
        children: [
          Container(
              child: ElevatedButton(
                onPressed: () {
                  setState(() {
                    i++;
                  });
                },
                child: Text('setState'),
              )
          ),
          MyStatelessWidget(),
        ]
      ),
    );
  }

  void onBackPressed(BuildContext context) {
    NavigatorState navigatorState = Navigator.of(context);
    if (navigatorState.canPop()) {
      navigatorState.pop();
    } else {
      SystemNavigator.pop();
    }
  }
}

class MyStatelessWidget extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    logger.print("PageB MyStatelessWidget build");
    return Container(
        child: ElevatedButton(
          onPressed: () {},
          child: Text('button'),
        )
    );
  }
}
